home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _1print.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  6.8 KB  |  200 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 51print.jsx 1.0.0.53 23-Feb-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Printing Support.
  18. // Note that once the printer has been loaded, it cannot be unloaded anymore.
  19. // Unloading the DLL makes the code of all print objects goaway, leading to
  20. // a crash, because the objects may still exist in the JavaScript world.
  21.  
  22. var printLib            = null;
  23. var printer             = null;
  24. var printerLoaded       = false;
  25. var printerAvailable    = true;     // first, assume that printing is available until a load fails
  26.  
  27. // return an RGB color array
  28. function getColor(color) {
  29.     var c = new Array ;
  30.     c[0] = (color & 0xff0000) >> 16 ; // R
  31.     c[1] = (color & 0x00ff00) >>  8 ; // G
  32.     c[2] = (color & 0x0000ff) >>  0 ; // B
  33.  
  34.     return c ;
  35. }
  36.  
  37. // copy the prefs color data to the printer
  38. function setPrinterColors(printer,prefs)
  39. {
  40.     var colors  = printer.colors                ;
  41.     colors[0]   = getColor(prefs.textColor)     ;
  42.     colors[1]   = getColor(prefs.errorColor)    ;
  43.     colors[2]   = getColor(prefs.keywordColor)  ;
  44.     colors[3]   = getColor(prefs.numberColor)   ;
  45.     colors[4]   = getColor(prefs.stringColor)   ;
  46.     colors[5]   = getColor(prefs.symbolColor)   ;
  47.     colors[6]   = getColor(prefs.operatorColor) ;
  48.     colors[7]   = getColor(prefs.commentColor)  ;
  49.  
  50.     printer.colors = colors ;
  51.  
  52. }
  53.  
  54. // setup the correct font for printing/previewing
  55. function setPrinterFont(printer,prefs)
  56. {
  57.     var bMac      = $.os.substr (0, 3) == "Mac" ;
  58.     var fontName  = prefs.fontName ;
  59.  
  60.     if ( bMac ) {
  61.         if ( fontName == "*serif"       ) fontName = localize("$$$/ESToolkit/Fonts/SerifMac=Times"        ) ;
  62.         if ( fontName == "*sansserif"   ) fontName = localize("$$$/ESToolkit/Fonts/SansSerifMac=Helvetica") ;
  63.         if ( fontName == "*monospace"   ) fontName = localize("$$$/ESToolkit/Fonts/MonospaceMac=Courier"  ) ;
  64.     } else {
  65.         if ( fontName == "*system"      ) fontName = localize("$$$/ESToolkit/Fonts/SystemWin=Arial Unicode MS"     ) ;
  66.         if ( fontName == "*application" ) fontName = localize("$$$/ESToolkit/Fonts/ApplicationWin=Arial Unicode MS") ;
  67.         if ( fontName == "*serif"       ) fontName = localize("$$$/ESToolkit/Fonts/SerifWin=Times New Roman"       ) ;
  68.         if ( fontName == "*sansserif"   ) fontName = localize("$$$/ESToolkit/Fonts/SansSerifWin=Arial Unicode MS"  ) ;
  69.         if ( fontName == "*monospace"   ) fontName = localize("$$$/ESToolkit/Fonts/MonospaceWin=Courier New"       ) ;
  70.     }
  71.  
  72.     printer.fontName = fontName ;
  73.     printer.fontSize = prefs.fontSize;
  74.     printer.fontFace = prefs.fontFace;
  75. }
  76.  
  77. function printerSelected()
  78. {
  79.     var result = false ;
  80.     try {
  81.       result = printer.printerNames.length > 0 ;
  82.     } catch ( e ) {} ;
  83.  
  84.  
  85.     try {
  86.       if ( !result ) {
  87.         printer = new PrintObject() ;
  88.       }
  89.       result = printer.printerNames.length > 0 ;
  90.     } catch ( e ) {} ;
  91.  
  92.     if ( !result ) {
  93.       errorBox(localize("$$$/ESToolkit/Alert/PrinterCountIsZero=Could not complete the Print command because the selected printer driver could not be found.  Please select a printer from the control panel and try again.")) ;
  94.     }
  95.  
  96.     return result ;
  97. }
  98.  
  99. // Load the priner on demand. Return true if the printer is operational.
  100.  
  101. function loadPrinter()
  102. {
  103.     if (!printerLoaded)
  104.     {
  105.         var printLibPath = Folder.appPackage.absoluteURI;
  106.         if ($.os.indexOf ("Mac") >= 0)
  107.             printLibPath += "/Contents/PlugIns/printinglib";
  108.         else // Win
  109.             printLibPath += "/Plug-Ins/printinglib";
  110.         try
  111.         {
  112.             printLib = new ExternalObject ("lib:" + printLibPath);
  113.         }
  114.         catch (e)
  115.         {
  116.             printLib = null;
  117.         }
  118.         printerLoaded = true;
  119.         if (!printLib)
  120.         {
  121.             errorBox ("$$$/ESToolkit/Alerts/NoPrinter=Cannot load the printing library; printing is not available.");
  122.             printerAvailable = false;
  123.         }
  124.         else
  125.             printer = new PrintObject;
  126.     }
  127.     return printerAvailable;
  128. }
  129.  
  130. var fileMenu            = MenuElement.find ("file");
  131. fileMenu.pageSetup      = MenuElement.find ("file/pageSetup");
  132. fileMenu.print          = MenuElement.find ("file/print");
  133. if ($.os.substr (0, 3) == "Win")
  134.     fileMenu.preview    = new MenuElement ( "command", 
  135.                                             localize ("$$$/ESToolkit/Menu/File/Preview=Print Pre&view"),
  136.                                             "after file/pageSetup", "file/preview");
  137.  
  138. fileMenu.pageSetup.enabled = printerAvailable;
  139.  
  140. fileMenu.print.onDisplay = function()
  141. {
  142.     this.enabled = printerAvailable && (document != null) ;
  143. }
  144.  
  145. if (fileMenu.preview)
  146.     fileMenu.preview.onDisplay = fileMenu.print.onDisplay;
  147.  
  148. fileMenu.pageSetup.onSelect = function()
  149. {
  150.     if (loadPrinter() && printerSelected() )
  151.         printer.printSetup();
  152. }
  153.  
  154. if (fileMenu.preview)
  155.     fileMenu.preview.onSelect = function()
  156. {
  157.     if (loadPrinter())
  158.     {
  159.         if (document.path)
  160.             printer.fileName = document.path;
  161.         else
  162.             printer.fileName = document.title;
  163.  
  164.         
  165.         setPrinterColors(printer,prefs) ;
  166.         setPrinterFont  (printer,prefs) ;
  167.  
  168.         printer.text = document.text;
  169.         printer.tabs = prefs.tabs;
  170.         printer.footer   = "%c%d";
  171.         printer.lineNumbers = prefs.lineNumbers;
  172.         printer.wrapLongLines = prefs.wrap;
  173.  
  174.         printer.preview(localize("$$$/ESToolkit/Alert/PrintPreviewTitle=Print Preview"));
  175.  
  176.     }
  177. }
  178.  
  179. fileMenu.print.onSelect = function()
  180. {
  181.     if (loadPrinter() && printerSelected() )
  182.     {
  183.         if (document.path)
  184.             printer.fileName = document.path;
  185.         else
  186.             printer.fileName = document.title;
  187.  
  188.         setPrinterColors(printer,prefs) ;
  189.         setPrinterFont  (printer,prefs) ;
  190.  
  191.         printer.text = document.text;
  192.         printer.tabs = prefs.tabs;
  193.         printer.footer   = "%c%d";
  194.         printer.lineNumbers = prefs.lineNumbers;
  195.         printer.wrapLongLines = prefs.wrap;
  196.  
  197.         printer.print();
  198.     }
  199. }
  200.